package com.hxz.admin.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hxz.admin.service.AdminCommentService;
import com.hxz.admin.service.impl.AdminCommentServiceImpl;
import com.hxz.entity.Article;
import com.hxz.entity.ArticleComment;

/**
 * 评论管理页面
 * @author hxz
 * @description TODO
 * @data 2019年12月5日 上午9:31:15
 */
@Controller
@RequestMapping("/admin/comments")
public class AdminCommentsController {
	@Autowired
	private AdminCommentService adminCommentsService;

	@RequestMapping("")
	public String getCommentsList(@RequestParam(value = "page", defaultValue = "1") int page,
			@RequestParam(value = "limit", defaultValue = "8") int limit, HttpServletRequest request) {
		PageHelper.startPage(page, limit);
		List<ArticleComment> articleCommentList = adminCommentsService.getCommentList();
		PageInfo<ArticleComment> pageInfo = new PageInfo<>(articleCommentList);
		request.setAttribute("articleCommentList", pageInfo);
		return "admin/comment_list";
	}

	@RequestMapping(value = "/delete")
	@ResponseBody
	public Map<String, String> deleteCommentById(@RequestParam(value = "id", required = true) Integer id,
			HttpServletRequest request) {
		Map<String, String> result = new HashMap<String, String>();
		Integer statusCode = adminCommentsService.deleteCommentById(id);
		if (statusCode > 0) {
			result.put("msg", "success");
		} else {
			result.put("msg", "fail");
		}
		return result;
	}
}
